package com.funtl.spring.cloud.alibaba.consumer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
    private final RestTemplate restTemplate;
    @Autowired
    public TestController(RestTemplate restTemplate){
        this.restTemplate=restTemplate;
    }

    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable("string") String string){
        // 使用服务名请求服务提供者
        return restTemplate.getForObject("http://service-provider/echo/" + string, String.class);
    }
}
